﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ch07
{
    //学生信息管理类
    class StudentManager
    {
        //定义学生集合的字段
        ArrayList stuList = new ArrayList();

        //添加学员的方法
        public void Add(Student stu)
        {
            stuList.Add(stu);
        }
        //删除学员的方法
        public void Delete(Student stu)
        {
            stuList.Remove(stu);
        }
        //查询学员的方法
        public void Query(int field,string value)
        {
            string fieldValue = "";
            
            Console.WriteLine("\n学号\t姓名\t年龄\t性别");
            foreach (Student stu in stuList)
            {
                switch (field)
                {
                    case 1: fieldValue = stu.StuNo.ToString(); break;
                    case 2: fieldValue = stu.StuName; break;
                    case 3: fieldValue = stu.StuAge.ToString(); break;
                    case 4: fieldValue = stu.StuSex.ToString(); break;
                }
                if (fieldValue == value)
                {
                    Console.WriteLine(stu);
                }
            }
        }
        //根据学号查询学员的方法
        public Student GetStuById(int id)
        {
            foreach (Student stu in stuList)
            {
                if (stu.StuNo == id)
                {
                    return stu;
                }
            }
            return null;
        }
        //查询所有学员的信息
        public ArrayList GetAllStus()
        {
            return stuList;
        }
    }
}

